<?php
namespace app\index\controller;
use app\common\controller\IndexController;
use ClassLibrary\ClHttp;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/6/17
 * Time: 10:46
 */
class Dome extends IndexController {
    public function index()
    {
        $data = [
            0=>[
               'id'=>11111,
               'name'=>'请问'
            ],
            1=>[
                'id'=>21111,'name'=>'ewq'
            ]
        ];
        $redis = new \Redis();

        $redis->connect('127.0.0.1', 6379);
        // $redis->auth('password'); # 如果没有密码则不需要这行

        //把 'test'字符串存入 redis
//        $redis->set('test_name', 'test');
//        // 把 'test_name' 的 值从 redis 读取出来
//        echo $redis->get('test_name');
//        $redis->lPush('user',json_encode($data,JSON_UNESCAPED_UNICODE));
//        $res1 = $redis->lRange('user',-4,0);
        $res = $redis->ZRANGE('zset',0,-1,true);
        $redis->PEXPIRE('zset',1500);
        dump($res);
    }

    public function zhabao($data,$url)
    {
        ClHttp::
        $data = json_encode($data);
        $ch = curl_init(); //初始化CURL句柄
        curl_setopt($ch, CURLOPT_URL, $url); //设置请求的URL
        curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //设为TRUE把curl_exec()结果转化为字串，而不是直接输出
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"PUT"); //设置请求方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//设置提交的字符串
        $output = curl_exec($ch);
        curl_close($ch);
        return json_decode($output,true);

    }
}